package com.wwp.tbshop.presenter;

import android.util.Log;
import android.widget.Toast;

import com.wwp.tbshop.activity.AddressManageActivity;
import com.wwp.tbshop.model.bean.AddressList;

import retrofit2.Call;

/**
 * Created by Xiaokun on 2017/6/16.
 */

public class AddressPresenter extends BasePresenter<AddressList>{

    private AddressManageActivity addressManageActivity;

    public AddressPresenter (AddressManageActivity addressManageActivity){
        this.addressManageActivity=addressManageActivity;
    }

    public void getAddressList(int userid){
        Call<AddressList> addressList = mApiService.getAddressList(userid);
        addressList.enqueue(mCallback);
    }

    @Override
    protected void onServerBug(int code) {
        Log.e("Addresspresenter", "onServerBug:"+code);
    }

    @Override
    protected void onConnectError(String message) {
        Toast.makeText(addressManageActivity,message,Toast.LENGTH_SHORT).show();
    }

    @Override
    protected void onSuccess(AddressList addressList) {
        String error_code = addressList.getError_code();
        if (error_code!=null){
            Toast.makeText(addressManageActivity,"亲，请先登陆",Toast.LENGTH_SHORT).show();
        }else {
            addressManageActivity.onSuccess(addressList);
        }
    }

}
